package shop;

import java.util.List;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

@Component
public class ListProductsService implements ListProducts{
	private JdbcTemplate db;
	
	@Autowired
	public void setDateSource(DataSource dataSource){
		this.db = new JdbcTemplate(dataSource);
	}
	
	@SuppressWarnings("unchecked")
	public List<Product> listAllProduct(){
		return (List<Product>)db.query("select * from product", new ProductMapper());
	}
}
